<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1、变量
        for(var i = 0; i < 3; i++) {
            setTimeout( () => console.log(i), 1) // 3 3 3
        }
        for(let i = 0; i < 3; i++) {
            setTimeout( () => console.log(i), 1) // 0 1 2
        }

        // 2、new 关键字
        function User(username, password){
            this.username = username;
            this.password = password;
        }
        const T1 = new User("small", "123456")
        T1; // User {username: "small", password: "123456"}
        const T2 = User("small", "123456");  // undefined

        // Javascript 控制
        function sum(n1, n2) { return n1 + n2; }
        sum(10, "20");  // 1020

        // 模板文字
        // function getCar(brand, model) {
        //     console.log(brand);
        //     console.log(model);
        // }
        // const brand = "Auids";
        // const model = "frits";
        // getCar`The brand of your car is ${brand} and the model is ${model}`;

        // Rest 参数
        function getCar(...args) {
            console.log(typeof args);
        }
        getCar('Auids', 'frits');

        // var 变量
        var A1 = 10;
        var A1 = 20;
        console.log(A1);

        // Continue声明
        for(let i = 1; i < 10; i++) {
            if( i === 5) continue;
            console.log(i);
        }

        // Array 
        const anArray = [1, 2, 3, 4, 5];
        anArray[10] = 100;
        console.log(anArray);

        // false && true
        console.log(!! null);
        console.log(!! 1);
        console.log(!! 0);
        console.log(!! '');
        console.log(!! true);
        console.log(!! false);

        // Map 
        [1, 2, 3, 4, 5].map( n => {
            if(n < 10) return;
            return n*2;
        })
    </script>
</body>
</html>